package shu;

import java.util.zip.Adler32;

public class _01TreeAndArray {
    public static void main(String[] args) {
        int[] arr = {78,56,34,43,4,1,15,2,23};
        System.out.print("先序遍历：");
        preOrder(arr,0);
        System.out.println();
        System.out.print("中序遍历:");
        inOrder(arr,0);
        System.out.println();
        System.out.print("后序遍历:");
        AfOrder(arr,0);
    }

    private static void preOrder(int[] arr, int index) {
        if (index >= arr.length){
            return;
        }
        System.out.print(arr[index] + " ");
        preOrder(arr,2*index+1);
        preOrder(arr,2*index+2);
    }

    private static void inOrder(int[] arr, int index) {
        if (index >= arr.length){
            return;
        }
        inOrder(arr,2*index+1);
        System.out.print(arr[index] + " ");
        inOrder(arr,2*index+2);
    }

    private static void AfOrder(int[] arr, int index) {
        if (index >= arr.length){
            return;
        }
        AfOrder(arr,2*index+1);
        AfOrder(arr,2*index+2);
        System.out.print(arr[index] + " ");
    }
}
